// 验证码相关
import {reactive} from "vue";
import {sendEmailVerficationCode} from "@/api/email";

export let getVerificationCodeBtn = reactive({
    text: "获取验证码",
    disable: false,
    second: 60,
    timer: null
})

export const getVerificationCode = (email) => {
    // 调用发送邮件接口
    sendEmailVerficationCode(email).then(res => {
        console.log(res)
    })
    if (getVerificationCodeBtn.timer) {
        clearInterval(getVerificationCodeBtn.timer)// 清除定时器
    }
    getVerificationCodeBtn.timer = setInterval(() => {
        if (getVerificationCodeBtn.second > 0) {
            if (!getVerificationCodeBtn.disable)
                getVerificationCodeBtn.disable = true
            getVerificationCodeBtn.second--
            getVerificationCodeBtn.text = getVerificationCodeBtn.second + "秒后可重发";
            console.log(getVerificationCodeBtn.second)
        } else {
            clearInterval(getVerificationCodeBtn.timer)
            getVerificationCodeBtn.second = 60
            getVerificationCodeBtn.text = "重发验证码"
            getVerificationCodeBtn.disable = false
        }
    }, 1000)
}